Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pre-built timezone/directory maps by default. #193

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

orlp
Copy link

@orlp orlp commented Jan 28, 2025

Resolves #192.

Now warns you if you have CHRONO_TZ_TIMEZONE_FILTER set but haven't enabled the filter-by-regex feature.

If the timezone information is updated one must run

cargo clean
CHRONO_TZ_UPDATE_PREBUILT=1 cargo build --all-features

before publishing the crate. You may want to put this in some form of CI to ensure this happens.

@orlp
Copy link
Author

orlp commented Jan 28, 2025

Compile times are down, but are still quite high. I think generating a binary encoded blob for the timespan information and attaching it with include_bytes! would be a significant boon. It would also reduce the size of the crate, as prebuilt_timezones.rs is 7MB worth of Rust code that has to get compiled. The only thing that would be needed is some offset calculation and the addition of some i32::from_le_bytes calls.

@orlp orlp changed the title Use pre-built timezone/directory maps. Use pre-built timezone/directory maps by default. Jan 28, 2025
@djc
Copy link
Member

djc commented Jan 29, 2025

Have you already looked at #165? Not sure if your ideas are aligned with that (or are complimentary).

@orlp
Copy link
Author

orlp commented Jan 29, 2025

@djc The idea is complimentary. You could choose to have such an encoding in the binary blob. The PRs would invalidate each other though.

#[cfg(not(feature = "filter-by-regex"))]
{
if std::env::var("CHRONO_TZ_TIMEZONE_FILTER").is_ok() {
println!("cargo:warning=CHRONO_TZ_TIMEZONE_FILTER set without enabling filter-by-regex feature")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the docs:

The warning instruction tells Cargo to display a warning after the build script has finished running. Warnings are only shown for path dependencies (that is, those you’re working on locally), so for example warnings printed out in crates.io crates are not emitted by default, unless the build fails.

Not sure this is useful?

(Also the docs seem to indicate it should be cargo::warning, with two colons.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe we also need to fail the build in that case, in addition to the warning. My hope was to give a simple warning without a hard failure.

I tried using cargo::warning but apparently that is new syntax. The single-colon syntax is required for the MSRV of chrono-tz.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've switched this now to use cargo::error which is only supported on newer versions. So either the library is larger than expected but still works on older versions, or you get a helpful error telling you to enable the feature.

Comment on lines 9 to 10
#[cfg(not(feature = "filter-by-regex"))]
include!("prebuilt_directory.rs");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead have #[path = "prebuilt_directory.rs"] on the mod declaration in lib.rs conditional on a cfg(), or does that not work? Otherwise, can we use a mod declaration here and re-export all symbols? I'd like the prebuilt modules to be visible to Rust-Analyzer et al.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that'd work (the first suggestion), I'll try it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I can't get this to work, because we need the OUT_DIR environment variable but the path attribute only accepts string literals.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth rust-analyzer seems to be able to pierce through the include! barrier.

Comment on lines 563 to 570
let src_dir = env::current_dir().unwrap();
let timezone_path = src_dir.join("src").join("prebuilt_timezones.rs");
let mut timezone_file = File::create(timezone_path).unwrap();
write_timezone_file(&mut timezone_file, &table).unwrap();

let directory_path = src_dir.join("src").join("prebuilt_directory.rs");
let mut directory_file = File::create(directory_path).unwrap();
write_directory_file(&mut directory_file, &table, &iana_db_version).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract the duplicated code out into a function instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@orlp
Copy link
Author

orlp commented Feb 3, 2025

@djc Could you take another look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ship pre-built library by default?
2 participants